package net.wanho.customerManage.service.impl;

import net.wanho.commons.exception.DaoException;
import net.wanho.commons.exception.ServiceException;
import net.wanho.commons.factory.BeanFactory;
import net.wanho.customerManage.dao.CustomerDao;
import net.wanho.customerManage.dao.LinkManDao;
import net.wanho.customerManage.po.Customer;
import net.wanho.customerManage.query.CustomerQuery;
import net.wanho.customerManage.service.CustomerService;
import net.wanho.customerManage.vo.CustomerVo;

import java.util.Date;
import java.util.List;

public class CustomerServiceImpl implements CustomerService {
    private CustomerDao customerDao = BeanFactory.getBean(CustomerDao.class) ;
    @Override
    public List<CustomerVo> selectAllCustomer() throws ServiceException {
        try {
            return customerDao.selectAllCustomer();
        } catch (DaoException e) {
            e.printStackTrace();
            throw new ServiceException(e.getMessage()) ;
        }
    }

    @Override
    public List<CustomerVo> selectByCondCustomer(CustomerQuery customerQuery) throws ServiceException {
        try {
            return customerDao.selectByCondCustomer(customerQuery) ;
        } catch (DaoException e) {
            e.printStackTrace();
            throw new ServiceException(e.getMessage()) ;
        }
    }

    @Override
    public CustomerVo selectByIdCustomer(Integer customerId) throws ServiceException {
        try {
            return customerDao.selectByIdCustomer(customerId) ;
        } catch (DaoException e) {
            e.printStackTrace();
            throw new ServiceException(e.getMessage()) ;
        }
    }

    @Override
    public Integer insertCustomer(Customer customer) throws ServiceException {
        try {
            customer.setCreateTime(new Date());
            customer.setUpdateTime(new Date());
            return customerDao.insertCustomer(customer) ;
        } catch (DaoException e) {
            e.printStackTrace();
            throw new ServiceException(e.getMessage()) ;
        }
    }
}
